﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sunboxsoft.WinForm
{
    public class ViewContext
    {
        public ViewStack Stack { get; private set; }

        public Dictionary<IView, ActionNodeCollection> ViewActionDict = new Dictionary<IView, ActionNodeCollection>();



        public ViewContext()
        {
            Stack = new ViewStack();
        }

        public ActionNodeCollection CreateActionCollection(IView view)
        {
            ActionNodeCollection collection = null;
            foreach (IView item in ViewActionDict.Keys)
            {
                if (item == view)
                {
                    collection = ViewActionDict[item];
                    break;
                }
            }

            if (collection == null)
            {
                collection = new ActionNodeCollection();
                ViewActionDict.Add(view, collection);
            }
            return collection;
        }

        public void RemoveActionCollection(IView view)
        {
            foreach (IView item in ViewActionDict.Keys)
            {
                if (item == view)
                {
                    ViewActionDict.Remove(item);
                    break;
                }
            }
        }

        public ActionNodeCollection GetActionCollection(IView view)
        {
            foreach (IView item in ViewActionDict.Keys)
            {
                if (item == view)
                {
                    return ViewActionDict[item];
                }
            }
            return null;
        }
    }
}
